<?php

namespace App\Http\Middleware;

use App\Http\Services\AuthService;
use App\Http\Services\LoginService;
use App\Http\Services\SchoolService;
use Closure;

class VerifyUser
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $admin = LoginService::getAdmin();
        if(empty($admin)){
            return redirect('login');
        }
        $admin['school'] = SchoolService::getSchoolInfo($admin['school_code']);
        $request->merge(['admin' => $admin]);
        return $next($request);
    }
}
